var deviceController = new function(){
	
	this.iOSDevice = "";
	this.ratio = "";
	
	//ratio entre el ancho real del dispositivo Apple y el ancho del canvas
	this.canvasRatio = "";
	
	this.iPhone = {
		width: 480,
		height: 320
	}
	this.iPad = {
		width: 1024,
		height: 768
	}
	
	var   _$deviceWindow	
		, _$iOSDeviceInput
		, _$overlay
	;
	
	function init(){
		
		_$deviceWindow = $('#deviceWindow');
		_$iOSDeviceInput = $('#iOSDevice');
		_$overlay = $('#device-window-overlay');

		_$deviceWindow.kendoWindow({
			  width: "700px"
			, height: "350px"
			, title: ""
			, modal: true
			, visible: false
			, draggable: false
			, resizable: false
		});
		
		_$deviceWindow.siblings().find('.k-window-actions').remove();
		
		_$deviceWindow.find('a').click(function(e){
			
			setDevice( $(this).attr('device') );
			mainInit();
			close();
		})
	}
	
	function show(){

		_$overlay.show();
		_$deviceWindow.data("kendoWindow").center().open();
		
		
		//Selección automática de dispositivo. 
		//Solo en entorno de desarrollo!
		if (env == "dev"){
			_$deviceWindow.find('a').eq(0).click();
			_$deviceWindow.data("kendoWindow").close();	
		}
	}
	
	function close(){
		
		_$overlay.hide();
		_$deviceWindow.data("kendoWindow").close();
	}
	
	function setDevice(p_device){

		deviceController.iOSDevice = p_device;
		deviceController.ratio = (deviceController.iOSDevice == "iPhone") 
			? deviceController.iPhone.height/deviceController.iPhone.width 
			: deviceController.iPad.height/deviceController.iPad.width;	
	
		_$iOSDeviceInput.text(p_device);
	}
	
	function setCanvasRatio(canvasWidth){

		deviceController.canvasRatio = canvasWidth / deviceController[deviceController.iOSDevice].width;
	}
	
	function getCocosHeight(h){
		
		var deviceHeight = deviceController[deviceController.iOSDevice].height;
		return deviceHeight - h;
	}
	
	function getDadaHeightFromCocos(h){
		
		var deviceHeight = deviceController[deviceController.iOSDevice].height;
		return deviceHeight - parseInt(h);
	}
	
	this.init = init;
	this.show = show;
	this.setDevice = setDevice;
	this.setCanvasRatio = setCanvasRatio;
	this.getCocosHeight = getCocosHeight;
	this.getDadaHeightFromCocos = getDadaHeightFromCocos;
}